local resX,resY = guiGetScreenSize()
--- XML
function loadTekst ()
	nodeCop = xmlLoadFile("cop.xml")
	nodeMedic = xmlLoadFile("medic.xml")
	tekstCop = xmlNodeGetValue(nodeCop)
	tekstMedic = xmlNodeGetValue(nodeMedic)
end
--- GUI
contract = guiCreateWindow(resX/10*3,resY/10*2.5,resX/10*4,resY/10*5,"Contract Job",false)
guiSetAlpha(contract,0.88)
tekst = guiCreateMemo(12,29,373,237,"",false,contract)
guiSetAlpha(tekst,1)
guiMemoSetReadOnly(tekst,true)
accept = guiCreateButton(12,322,163,31,"Accept",false,contract)
guiSetAlpha(accept,1)
help = guiCreateButton(193,330,25,25,"?",false,contract)
guiSetAlpha(help,1)
cancel = guiCreateButton(235,322,163,31,"Cancel",false,contract)
guiSetAlpha(cancel,1)
guiSetVisible(contract,false)
guiWindowSetMovable(contract,false)
guiWindowSetSizable(contract,false)

contract_help = guiCreateWindow(resX/10*3,resY/10*3.7,232,144,"contract help",false)
guiSetAlpha(contract_help,1)
tekst_help = guiCreateMemo(9,27,214,77,"Read the rules.\npress accept or cancel job\ncheers.",false,contract_help)
guiSetAlpha(tekst_help,1)
guiMemoSetReadOnly(tekst_help,true)
help_close = guiCreateButton(42,107,151,28,"Close",false,contract_help)
guiSetAlpha(help_close,1)
guiSetVisible(contract_help,false)
guiWindowSetMovable(contract_help,false)
guiWindowSetSizable(contract_help,false)
--- Get all markers
pjm = { pjm1 }
mjm = { mjm1 }
--- The functions
function openPoliceGUI(hitPlayer, matchingDimension)
	if (source == pjm) then
		guiSetVisible(contract,true)
		showCursor(true)
	elseif (source == mjm) then
		guiSetVisible(contract,true)
		showCursor(true)
	end
end
function openPoliceGUICommand (command)
	if (source == cop) then
		guiSetVisible(contract,true)
		showCursor(true)
		guiSetText(tekst, tekstCop)
	elseif (source == medic) then
		guiSetVisible(contract,true)
		showCursor(true)
		guiSetText(tekst, tekstMedic)
	end
end
function acceptGUI(thePlayer, command)
	if (source == accept) then
		if (source == cop) then
			guiSetVisible (contract, false)
			guiSetVisible (contract_help, false)
			showCursor(false)
			outputChatBox("You have accept the Police job.", 255, 255, 10)
			triggerServerEvent("onPoliceJobAccept", getRootElement())
		elseif (source == medic) then
			guiSetVisible (contract, false)
			guiSetVisible (contract_help, false)
			showCursor(false)
			outputChatBox("You have accept the Medic job.", 255, 255, 10)
			triggerServerEvent("onMedicJobAccept")
		end
	end
end
function helpGUI()
	if (source == help) then
		guiSetVisible (contract_help, true)
	end
end
function helpGUIClose()
	if (source == help_close) then
		guiSetVisible (contract_help, false)
	end
end	
function closeGUI()
	if (source == cancel) then
		guiSetVisible (contract, false)
		guiSetVisible (contract_help, false)
		showCursor(false)
	end
end
--- Handlers
addCommandHandler("cop",openPoliceGUICommand)
addCommandHandler("medic",openPoliceGUICommand)
addEventHandler("onClientMarkerHit",getRootElement(),openGUI)
addEventHandler("onClientGUIClick",accept,acceptGUI,false)
addEventHandler("onClientGUIClick",help,helpGUI,false)
addEventHandler("onClientGUIClick",help_close,helpGUIClose,false)
addEventHandler("onClientGUIClick",cancel,closeGUI,false)